﻿namespace Sidvall.AuthorizationManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class FilterContext : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.AuthorizationManager.Data.IFilterContext
    {
        #region Public Members

        #region AuthorizationScopeId

        private System.Nullable<long> _AuthorizationScopeId;
        partial void OnBeforeAuthorizationScopeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData);
        partial void OnAfterAuthorizationScopeIdPropertyChanged();
        public System.Nullable<long> AuthorizationScopeId
        { 
            get
            {
                return _AuthorizationScopeId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _AuthorizationScopeId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<long>>(value, _AuthorizationScopeId);
                    OnBeforeAuthorizationScopeIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("AuthorizationScopeId", eventData.Value, true, true);
                        OnAfterAuthorizationScopeIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region FilterContextId

        private System.Nullable<int> _FilterContextId;
        partial void OnBeforeFilterContextIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData);
        partial void OnAfterFilterContextIdPropertyChanged();
        public System.Nullable<int> FilterContextId
        { 
            get
            {
                return _FilterContextId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _FilterContextId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<int>>(value, _FilterContextId);
                    OnBeforeFilterContextIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("FilterContextId", eventData.Value, true, true);
                        OnAfterFilterContextIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.FilterContextManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.FilterContextManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.FilterContextManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public FilterContext Copy()
        {
            return global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.FilterContextManager.Copy(this);
        }
        public FilterContext Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.FilterContextManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.AuthorizationManager.Data.IFilterContext item)
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.FilterContextManager.Import(this, item);
        }
        public void Import(global::Sidvall.AuthorizationManager.Data.IFilterContext item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.FilterContextManager.Import(this, item, settings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.FilterContextManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.FilterContextManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.FilterContextManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.FilterContextManager.Initialize(this, settings);
        }

        #endregion

        #region IFilterContext Members

        System.Nullable<long> global::Sidvall.AuthorizationManager.Data.IFilterContext.AuthorizationScopeId
        {
            get
            {
                return this._AuthorizationScopeId;
            }
            set
            {
                this._AuthorizationScopeId = value;
            }
        }
        System.Nullable<int> global::Sidvall.AuthorizationManager.Data.IFilterContext.FilterContextId
        {
            get
            {
                return this._FilterContextId;
            }
            set
            {
                this._FilterContextId = value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public FilterContext()
        {
        }
        public FilterContext(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public FilterContext(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.AuthorizationManager.SystemContextConfig.Current.EntityFacade.FilterContextManager.Initialize(this);
        }

        #endregion
    }
}